﻿using System.Linq.Expressions;

namespace Entropy.Ext
{
    public class EventObject
    {
        public int[] getXY()
        {
            return null;
        }

        public void stopEvent()
        {
        }

        public int getKey()
        {
            return 0;
        }

        public int ENTER { get; set; }
    }

    [JsClass("Ext.grid.Panel", "gridpanel")]
    public interface IGridPanel : IPanelTable
    {
    }


    [JsClass("Ext.grid.property.Grid", "propertygrid")]
    public interface IPropertyGrid : IGridPanel
    {
    }


    [JsClass("Ext.grid.plugin.Editing", "editing")]
    public interface IGridEditorPlugin : IAbstractPlugin
    {

    }

    [JsClass("Ext.AbstractPlugin", null)]
    public interface IAbstractPlugin : IBase
    {
    }

    [JsClass("Ext.grid.plugin.RowEditing", "rowediting")]
    public interface IGridPluginRowEditing : IGridEditorPlugin
    {
    }


    [JsClass("Ext.data.Model", null)]
    public interface IModel
    {
        /// <summary>
        /// Returns the value of the given field
        /// Available since: Ext 1
        /// </summary>
        /// <param name="fieldName">String
        ///  The field to fetch the value for</param>
        /// <returns>Object
        /// The value</returns>
        object get(string fieldName);
        void set(string fieldName, object value);
    }

    [JsClass("Ext.data.TreeModel", null)]
    public interface ITreeModel : IModel
    {
        INodeInterface data { get; }
    }

    public class EditEvent
    {
        /// <summary>
        /// The grid
        /// </summary>
        public IGridPanel grid;

        /// <summary>
        /// The record being edited
        /// </summary>
        public IModel record;

        /// <summary>
        /// The field name being edited
        /// </summary>
        public string field;

        /// <summary>
        /// The value for the field being edited.
        /// </summary>
        public object value;

        /// <summary>
        /// The grid table row
        /// </summary>
        public int row;

        /// <summary>
        /// The grid Column defining the column that is being edited.
        /// </summary>
        public int column;

        /// <summary>
        /// The row index that is being edited
        /// </summary>
        public int rowIdx;

        /// <summary>
        /// The column index that is being edited
        /// </summary>
        public int colIdx;

        /// <summary>
        /// Set this to true to cancel the edit or return false from your handler.
        /// </summary>
        public bool cancel;

        /// <summary>
        /// Alias for value (only when using CellEditing).
        /// </summary>
        public object originalValue;
    }

    public delegate bool GridCanEditEvent(IGridEditorPlugin editor, EditEvent e, object eOpt);
    public delegate void GridEditEvent(IGridEditorPlugin editor, EditEvent e, object eOpt);
    public delegate void GridContextMenu(EventObject e, object eOpt, IView view);

    [JsClass("Ext.panel.TableView", "tablepanel")]
    public interface IPanelTable : IPanelPanel
    {
        Expression<GridContextMenu> containercontextmenu { get; set; }
        Expression<GridCanEditEvent> beforeedit { get; set; }
        Expression<GridEditEvent> edit { get; set; }
        /// <summary>
        /// Returns the selection model being used and creates it via the configuration if it has not been created already.
        /// Available since: Ext 4
        /// Returns  Ext.selection.Model
        /// </summary>
        /// <returns></returns>
        ISelectionModel getSelectionModel();
    }
}